Answer:

The program will print out:

The value is:   17

Same Variable Twice in a LET Statement

Look at the statements:

LET VALUE = 5
LET VALUE = 12 + VALUE

The first statement:

  1. Found memory for VALUE since it has not been used before.
  2. Got the number on the RIGHT of the equal sign: 5
  3. Put the 5 in the memory called VALUE.

The second statement:

  1. Found no new memory, since the variable has been used before.
  2. Does the calculation on the RIGHT of the equal sign: 12 + VALUE.
    • It looks into the variable VALUE to get the number 5.
    • Then it performs the sum: 12 + 5 resulting in 17
  3. It now looks on the LEFT of the equal sign to see where to put the result. Now puts the 17 in the memory called VALUE.

Important Note:

A variable can be used on both the LEFT and the RIGHT of the "=" in the same LET statement. When it is used on the right, it provides a number used to calculate a result. When it is used on the left, it says where in memory to save that result.

The two roles are in separate steps, so they don't interfere with each other. Step 2 uses the old value in the variable for the calculation. Then the new value (from the calculation) is put into the variable.

QUESTION 8:

What will the following program print out:

' More example LET statements
LET VALUE = 5
PRINT "Value is:", VALUE
'
LET VALUE = VALUE + 10
PRINT "Now the value is:", VALUE
END